<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('认证列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="role-form">
                <div class="select-list">
                    <ul>
                        <li>
                            认证源名称：<input type="text" name="authName"/>
                        </li>
                        <li>
                            类型：<select name="type" th:with="type=${@dict.getType('sys_auth_way')}">
                            <option value="">所有</option>
                            <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                    th:value="${dict.dictValue}"></option>
                        </select>
                        </li>
                        <li>
                            认证源状态：<select name="status" th:with="type=${@dict.getType('sys_normal_disable')}">
                            <option value="">所有</option>
                            <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                    th:value="${dict.dictValue}"></option>
                        </select>
                        </li>
                        <li class="select-time">
                            <label>创建时间： </label>
                            <input type="text" class="time-input" id="startTime" placeholder="开始时间"
                                   name="params[beginTime]"/>
                            <span>-</span>
                            <input type="text" class="time-input" id="endTime" placeholder="结束时间"
                                   name="params[endTime]"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success multiple disabled" onclick="$.operate.copyAll()" shiro:hasPermission="system:auth:copy">
                <i class="fa fa-plus"></i> 复制
            </a>
            <a class="btn btn-primary single disabled" onclick="$.operate.edit()"
               shiro:hasPermission="system:auth:edit">
                <i class="fa fa-edit"></i> 修改
            </a>
            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()"
               shiro:hasPermission="system:auth:remove">
                <i class="fa fa-remove"></i> 删除
            </a>
        </div>

        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('system:auth:edit')}]];
    var removeFlag = [[${@permission.hasPermi('system:auth:remove')}]];
    var datas = [[${@dict.getType('sys_auth_way')}]];

    var prefix = ctx + "system/auth";


    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            copyUrl: prefix + "/copy",
            sortName: "sort",
            modalName: "认证源",
            columns: [{
                checkbox: true
            },
                {
                    field: 'authId',
                    title: '认证源编号'
                },
                {
                    field: 'authName',
                    title: '认证源名称',
                    sortable: true
                },
                {
                    visible: editFlag !== 'hidden',
                    title: '认证源状态',
                    align: 'center',
                    formatter: function (value, row, index) {
                        return statusTools(row, 'status');
                    }
                },
                {
                    field: 'type',
                    title: '类型',
                    sortable: true,
                    formatter: function (value, item, index) {
                        return $.table.selectDictLabel(datas, item.type);
                    }
                },
                {
                    field: 'clientName',
                    title: 'client_name',
                    sortable: false
                },
                {
                    field: 'localServer',
                    title: '当前访问地址',
                    sortable: false
                },
                {
                    field: 'authUrl',
                    title: '认证服务地址',
                    sortable: false
                },
                {
                    field: 'logoutUrl',
                    title: '登出地址',
                    sortable: false
                },
                {
                    field: 'sort',
                    title: '显示顺序',
                    sortable: true
                },
                {
                    field: 'createTime',
                    title: '创建时间',
                    sortable: true
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.authId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        if (row.initial === 1) {
                            actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.authId + '\')"><i class="fa fa-remove"></i>删除</a> ');
                        }
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });


    /* 认证源状态显示 */
    function statusTools(row, field) {
        if (row[field] === 1) {
            return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="enable(\'' + row.authId + '\', \'' + field + '\')"></i> ';
        } else {
            return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="disable(\'' + row.authId + '\', \'' + field + '\')"></i> ';
        }
    }

    function disable(authId, field) {
        if (field === 'status') {
            $.modal.confirm("确认要停用认证源吗？", function () {
                $.operate.post(prefix + "/changeStatus", {"authId": authId, "status": 1});
            })
        } else {
            $.modal.confirm("确认要取消该认证源为默认吗？", function () {
                $.operate.post(prefix + "/changeDefault", {"authId": authId, "show": 1});
            })
        }
    }

    function enable(authId, field) {
        if (field === 'status') {
            $.modal.confirm("确认要启用认证源吗？", function () {
                $.operate.post(prefix + "/changeStatus", {"authId": authId, "status": 0});
            })
        } else {
            $.modal.confirm("确认要设置该认证源为默认吗？", function () {
                $.operate.post(prefix + "/changeDefault", {"authId": authId, "show": 0});
            })
        }

    }
</script>
</body>
</html>